package com.wmx.jmm;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**********************************
 * @author wmx
 * @date 2019/9/27 11:42
 * @description:
 * @version 1.0
 ************************************/
@Slf4j
public class JMMDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                int a = Data.countDown;
                log.info(Thread.currentThread().getName()+"前："+a);
                a += 1;
                log.info(Thread.currentThread().getName()+"后："+a);
                Data.countDown = a;
            }
        });
        thread.setName("线程1");
        Thread thread1 = new Thread(() -> {
            int a = Data.countDown;
            log.info(Thread.currentThread().getName()+"前："+a);
            a += 1;
            log.info(Thread.currentThread().getName()+"后："+a);
            Data.countDown = a;

        });
        thread1.setName("线程2");

        thread.start();
        thread1.start();
        thread.join();
        thread1.join();
       TimeUnit.SECONDS.sleep(5);
       log.info("最后Data.countDown的值{}",Data.countDown);
    }


    static class Data {
        private static int countDown;
    }
}
